package com.team.childapp.ui.my

import com.team.childapp.R
import com.team.childapp.base.App
import com.team.childapp.base.activity.BaseActivity
import com.team.childapp.base.listener.ICallBackResultListener
import com.team.childapp.bean.login.UserInfoBean
import com.team.childapp.config.BaseConfig
import com.team.childapp.databinding.ActivityMyBinding
import com.team.childapp.http.MyInfoLogical
import com.team.childapp.ui.MainActivity
import com.team.childapp.ui.dialog.DatePickerDialogFragment

/**
 * Create on: 2024/12/26
 * by Mr.Zhu
 * Description: 设置信息页面
 */
class MyActivity : BaseActivity<ActivityMyBinding>(R.layout.activity_my) {
    private var currentSelect : Int = 1 //当前默认头像选择
    private var currentSex : Int = 0 //性别 0 是男 1是女
    private lateinit var datePickerDialogFragment: DatePickerDialogFragment
    override fun initData() {

        mBinding.rightIcon.setOnClickListener {
            start<MainActivity>()
        }
        setInfoInit()
        getUserInfo()
    }
    //性别和年龄的设置
    private fun setInfoInit() {
        var userSex= App.application().getShareData().getInt(BaseConfig.USER_SEX)
        mBinding.layoutSelectAge.setOnClickListener {
            if (!datePickerDialogFragment.isAdded) {
                datePickerDialogFragment.show(fragmentManager, "DatePickerDialogFragment")
            }
        }
        // 初始化日期选择器对话框
        datePickerDialogFragment = DatePickerDialogFragment().apply {
            setOnDateChooseListener { year, month, day ->
                mBinding.tvSelectAge.text = "$year-$month-$day"
            }
        }
    }

    private fun getUserInfo(){
        var deviceCode="1111"
        MyInfoLogical.getInstanceMyInfo().getDeviceInfo(this,deviceCode,
            object : ICallBackResultListener {
                override fun onCallBack(result: Any?) {
                    println("回调执行了，result: $result") // 打
                    if (result == null) {
                        return
                    }
                    val userInfo: UserInfoBean = result as UserInfoBean? ?: return
                    mBinding.edNickName.setText(userInfo.userName)
//                    mBinding.tvSelectAge.setText(userInfo.)
                }
            })
    }
}